﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class BalanceCenter_TryForSurrogate : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string Return = "";
        _User.GetUserInfoByID(ref Return);

        if (_User.isSurrogate)
        {
            Panel1.Visible = true;
            Panel2.Visible = false;
            Panel3.Visible = false;
            labTip.Text = "您已经是代理商了！";

            return;
        }

        labContent.Text = PublicFunction.GetOptionsBin("代理商协议");

        DataTable dt = DAL.Tables.T_TryForSurrogate.Select("top 1 [DateTime]", "[User_id]=" + _User.ID.ToString(), "[DateTime] desc");

        string TryForDateTime = "";
        try
        {
            TryForDateTime = dt.Rows[0][0].ToString();
            if (TryForDateTime == null)
            {
                TryForDateTime = "";
            }

            if (TryForDateTime != "")
            {
                Panel1.Visible = true;
                Panel2.Visible = false;
                labTip.Text = "您已经于" + TryForDateTime + "申请代理商了，请等待答复，谢谢！";

                return;
            }
        }
        catch
        { }

        Panel1.Visible = false;
        Panel2.Visible = true;
        Panel3.Visible = false;

        if (!this.IsPostBack)
        {
            btnAccept.Attributes.Add("onclick", "return confirm('" + System.Web.HttpUtility.HtmlEncode("您确信要申请成为代理商吗？") + "');");
        }
    }

    #region Web 窗体设计器生成的代码

    override protected void OnInit(EventArgs e)
    {
        isRequestLogin = true;
        SecondLevelPassword = true;
        RequestLoginPage = "BalanceCenter/TryForSurrogate.aspx";

        base.OnInit(e);
    }

    #endregion

    protected void btnAccept_Click(object sender, EventArgs e)
    {
        int Result = 0;
        string Return = "";
        if (DAL.Procedures.P_TryForSurrogate.Call(_User.ID, ref Result, ref Return) < 0)
        {
            ShoveEL._Web.JavaScript.Alert(this, "数据库连接失败");

            return;
        }

        if (Result < 0)
        {
            ShoveEL._Web.JavaScript.Alert(this, Return);

            return;
        }

        Panel1.Visible = false;
        Panel2.Visible = false;
        Panel3.Visible = true;
    }
}